#include <QObject>
#include <QPushButton>
#include <QTimer>
#include "mainwindow.h"
#include "debugwindow.h"
#include <QIcon>

debugwindow::debugwindow(QWidget *parent)
{
    test.setParent(this);
    test.setText("test");
    //test.setMaximumSize(50,50);
    // test.setMinimumSize(50,50);
    test.show();
    //a.setParent(this);
    //a.move(50,50);
    //a.show();
    icon_init(&a,50,30);
    icon_init(&star_num,50,45);
    icon_init(&star_res,50,60);
    icon_init(&star_poplim,50,75);
    icon_init(&star_pop,50,90);
    icon_init(&star_owner,50,105);
    icon_init(&civ_num,50,120);
    icon_init(&civ_res,50,135);
    icon_init(&civ_owned,50,150);
    icon_init(&civ_income,50,165);
    icon_init(&civ_total_pop,50,180);
    move(900,0);
    setFixedSize(300,600);

    QTimer *timer = new QTimer(this);   //初始化一个定时器。
    connect(timer, &QTimer::timeout, this, &debugwindow::update);   //设置信号与槽 ，槽函数update()需要再类中声明一下。
    timer->start(10 / 1);    //设置定时器刷新频率，即变量刷新频率。


    //setWindowFlags(Qt::CustomizeWindowHint|Qt::FramelessWindowHint);
    show();
}

void debugwindow::icon_init(QLabel* n, int x,int y)
{
    n->setParent(this);
    n->move(x,y);
    n->show();
}

void debugwindow::update()
{
    if(showing!=NULL)
    {
        char buffer[256];

        sprintf(buffer, "资源:%d",showing->res);
        star_res.setText(buffer);
        star_res.setText(buffer);
        star_res.adjustSize();

        sprintf(buffer, "人口上限:%d",showing->poplim);
        star_poplim.setText(buffer);
        star_poplim.setText(buffer);
        star_poplim.adjustSize();

        sprintf(buffer, "人口数量:%d",showing->pop);
        star_pop.setText(buffer);
        star_pop.setText(buffer);
        star_pop.adjustSize();


        sprintf(buffer, "星系序号:%d",showing->n);
        star_num.setText(buffer);
        star_num.setText(buffer);
        star_num.adjustSize();


        if(showing->owner!=NULL)
        {
            sprintf(buffer, "文明存储资源:%d",showing->owner->resource);
            civ_res.setText(buffer);
            civ_res.setText(buffer);
            civ_res.adjustSize();
            civ_res.show();

            sprintf(buffer, "星系所有者:%d号文明",showing->owner->num);
            star_owner.setText(buffer);
            star_owner.setText(buffer);
            star_owner.adjustSize();
            star_owner.show();

            sprintf(buffer, "文明占有星系数:%d",showing->owner->owned);
            civ_owned.setText(buffer);
            civ_owned.setText(buffer);
            civ_owned.adjustSize();
            civ_owned.show();

            sprintf(buffer, "文明收入:%f",showing->owner->income);
            civ_income.setText(buffer);
            civ_income.setText(buffer);
            civ_income.adjustSize();
            civ_income.show();

            sprintf(buffer, "文明总人口:%d",showing->owner->total_pop);
            civ_total_pop.setText(buffer);
            civ_total_pop.setText(buffer);
            civ_total_pop.adjustSize();
            civ_total_pop.show();
        }
        if(showing->owner==NULL)
        {
            civ_res.hide();
            civ_owned.hide();
            star_owner.hide();
            civ_income.hide();
            civ_total_pop.hide();


        }
    }
}
/*    QLabel star_res;//选中星系资源
QLabel star_poplim;//选中星系人口上限
QLabel star_pop;//选中星系总人口
QLabel star_owner;//选中星系所属文明
QLabel star_num;//选中星系序号
QLabel civ_num;//选中文明序号
QLabel civ_res;//选中文明资源存储
QLabel civ_owned;//选中文明拥有星系数量*/

